/*************************************************
Author: byron
Date: 10/16/2012
Description:
Notes:
*************************************************/

#ifndef __CUserPartner_h__
#define __CUserPartner_h__

#include "commclass.h"
#include "../skill/CSkillCfg.h"
#include "../skill/CSkill.h"

class CBattleMgr;
class CSkillMgr;
class CPartnerCfgData;
class CPartnerMgr;
class CUserPartner;
class CPlayerOnlineData;

class CPartnerUnit
{
public:
    CPartnerUnit()
    {
        Clear();
    }

    void Clear()
    {
        _shResID = 0;
        _iFighting = 0;
        _stAttr.Clear();
        _stNormalSkill.Clear();
        _stMagicSkill.Clear();
    }

    virtual ~CPartnerUnit()
    {
    }

    int GetFighting() const {return _iFighting;}

    int InitByCfg(CPartnerCfgData& stCfgData);

    int InitByListData(CPartnerCfgData& stCfgData,
            CPartnerListData& stListData);

    int CalcExtAttr(CPartnerCfgData& stCfgData, CPartnerActData& stActData);

    int ReCalcExtAttr(CPartnerActData& stActData, CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1, bool bNotifyPartnerInfo,
            bool bSendTeamFighting);

    int InitByActData(CPartnerCfgData& stCfgData, CPartnerActData& stActData,
            CPlayerBaseInfo& stPlayerBase, CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1);

    int TransToListData(CPartnerActData& stActData,
            CPartnerListData& stListData);

    int TransToActData(CPartnerActData& stActData);

    int TransToActData(CPartnerListData& stListData,
            CPartnerActData& stActData);

    CPlayerAttr& GetAttr() {return _stAttr;}

public:
    short                   _shResID;               //资源ID
    int                     _iFighting;             //战斗力

    CPlayerAttr             _stAttr;                //属性

    CSkill                  _stNormalSkill;         //普通技能
    CSkill                  _stMagicSkill;          //幻化技能
};

class CUserPartner
{
public:
    CUserPartner()
    {
        Clear();
    }

    void Clear ()
    {
        _astOnlineData.Clear();
    }

    virtual ~CUserPartner()
    {
    }

    bool IsOnlinePartner(short shResID);

    bool IsFullOnlinePartner() const
    {
        return _astOnlineData.Size() >= MAX_PARTNER_ACT_COUNT;
    }

    int AddPartner(CPartnerUnit& stPartnerUnit);

    int DelPartner(short shResID);

    int FindPartner(short shResID);

    CPartnerUnit& GetPartner(int iIndex){return _astOnlineData[iIndex];}

    //重新计算所有伙伴的属性
    int AllReCalcExtAttr(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1);

    int ReCalcExtAttr(short shResID, CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1, bool bNotifyPartnerInfo, 
            bool bSendTeamFighting);

    int UpLevel(short shResID, int iAddExp, CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1);

    int AddExp(short shResID, int iAddExp, CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1);

public:
    CTLib::CTArray<CPartnerUnit, MAX_PARTNER_ACT_COUNT> _astOnlineData;
};

#endif // __CUserPartner_h__

